<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="edu.unsw.comp9321.jdbc.*, java.util.*"%>
<jsp:useBean id="booking"
	class="edu.unsw.comp9321.common.BookingBean" scope="session" />
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
		<title>Welcome to CarRental</title>
		<link href="CSS.css" rel="stylesheet" type="text/css">
	</head>
	<body>
		<div id="pagehdr">
			<h1>Car Rental reservation system</h1>
		</div>
		<%
		if (request.getAttribute("violation") != null) {
			if (!request.getAttribute("violation").equals("noViolation")) {
			out.write("<br/><span style=\"color:red\"><strong>"
				+ request.getAttribute("violation") +"</strong></span><br/>");
			%>
			
			<p>To view your booking details you must provide us your PIN code which was sent to you by email at the time of booking.</p><br/>
			<p>Remember that you cannot view your booking details less than 48 hours before your booking start date.</p>
			<br/>
			<form action="controller" method="POST">
			<i>Please insert your PIN to check your booking:</i><input type="number" name="pin" min="1" size="5" maxlength="5">
			<input type="hidden" name="bookingId" value="${param.bookingId}"/>
			<input type="hidden" name="op" value="viewBooking"/>
			<input type="submit" value="View booking details"/>
			</form>
			
			<%
			
			} else {
				// print booking details
				%>
				<h2>Booking details</h2><br/>
				<table border="1" style="text-align:center">
					<tr>
						<th>Booking ID</th>
						<th>Customer name</th>
						<th>Class</th>
						<th>Make and Model</th>
						<th>Body Type</th>
						<th>Transmission Type</th>
						<th> </th>
						<th>Booking Date</th>
						<th>Start Date</th>
						<th>End Date</th>
						
					</tr>	
					<tr>
						<td>${booking.booking.id}</td>
						<td>${booking.booking.customerName}</td>
						<td>${booking.carType.typeClass}</td>
						<td>${booking.carType.makeModel}</td>
						<td>${booking.carType.bodyType}</td>
						<%
						if(booking.getCarType().isAutomatic()){
							out.write("<td>Automatic</td>");
						} else {
							out.write("<td>Manual</td>");
						}
						out.write("<td><img src=\""+request.getContextPath()+"/cars_pics/carType_"+booking.getCarType().getId()+"_picture.jpg\" height=\"100\"/></td>");
						out.write("<td>"+booking.getBooking().getBookingDate()+"</td>");
						out.write("<td>"+booking.getBooking().getStartDate()+"</td>");
						out.write("<td>"+booking.getBooking().getEndDate()+"</td>");
						%>
						
					</tr>
				</table>
				<br/>
				<form action="controller" method="POST">
				<input type="hidden" name="bookingId" value="${booking.booking.id}"/>
				<input type="hidden" name="op" value="deleteBooking"/>
				<input type="submit" value="Delete this booking"/>
			</form>
				<%
			}
		} else {
		%>

			<br/>
			<br/>
			<p>To view your booking details you must provide us your PIN code which was sent to you by email at the time of booking.</p><br/>
			<p>Remember that you cannot view your booking details less than 48 hours before your booking start date.</p>
			<br/>
			<form action="controller" method="POST">
			<i>Please insert your PIN to check your booking:</i><input type="number" name="pin" min="1" size="5" maxlength="5">
			<input type="hidden" name="bookingId" value="${param.bookingId}"/>
			<input type="hidden" name="op" value="viewBooking"/>
			<input type="submit" value="View booking details"/>
			</form>
		<%			
			
			
		}
		%>
	</body>
</html>